package leetcode;

import javax.swing.tree.TreeNode;

/**
 * 把二叉搜索树转变为累加数
 */
public class Solution25 {

    int sum = 0;
    public TreeNode convertBST(TreeNode root) {
        sum = 0;
        convertBST1(root);
        return root;
    }

    public void convertBST1(TreeNode cur){
        if(cur == null){
            return ;
        }
        convertBST1(cur.right);
        sum += cur.val;
        cur.val = sum;
        convertBST1(cur.left);
    }
}
